package com.heima.wemedia.controller.v1;

import com.heima.common.constants.WemediaConstants;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmMaterialDto;
import com.heima.wemedia.service.WmMaterialService;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("api/v1/material")
public class WmMaterialController {

    @Autowired
    WmMaterialService materialService;

    /**
     * 素材上传
     * @param file
     * @return
     */
    @PostMapping("upload_picture")
    public ResponseResult upload(@RequestParam("multipartFile") MultipartFile file){
        return materialService.upload(file);
    }


    /**
     * 素材列表
     * @param dto
     * @return
     */
    @PostMapping("list")
    public ResponseResult list(@RequestBody WmMaterialDto dto){
        return materialService.list(dto);
    }

    /**
     * 删除素材
     * @param id
     * @return
     */
    @GetMapping("del_picture/{id}")
    public ResponseResult del(@PathVariable("id") Integer id){
        return materialService.del(id);
    }

    /**
     * 收藏
     * @param id
     * @return
     */
    @GetMapping("collect/{id}")
    public ResponseResult collect(@PathVariable("id") Integer id){
        return materialService.collectOrCancelCollect(WemediaConstants.COLLECT_MATERIAL, id);
    }
    /**
     * 取消收藏
     * @param id
     * @return
     */
    @GetMapping("cancel_collect/{id}")
    public ResponseResult cancelCollect(@PathVariable("id") Integer id){
        return materialService.collectOrCancelCollect(WemediaConstants.CANCEL_COLLECT_MATERIAL, id);
    }


}
